package com.atguigu.java;

import org.junit.Test;

import java.io.*;

public class InputStreamReaderTest {
    @Test
    public void test() throws IOException {
        FileInputStream fis = new FileInputStream("dbcp.txt");
        InputStreamReader isr = new InputStreamReader(fis, "utf-8");
        char[] chars = new char[20];
        int len;
        while((len=isr.read(chars))!=-1){
            String str=new String(chars,0,len);
            System.out.println(str);
        }
        isr.close();
    }
    @Test
    public void test1() throws IOException {
        File f1 = new File("dbcp.txt");
        File f2 = new File("dbcp_gbk.txt");
        FileInputStream fis = new FileInputStream(f1);
        FileOutputStream fos = new FileOutputStream(f2);
        InputStreamReader isr = new InputStreamReader(fis,"utf-8");
        OutputStreamWriter osw = new OutputStreamWriter(fos,"gbk");
        char[] chars = new char[20];
        int len;
        while((len=isr.read(chars))!=-1){
            osw.write(chars,0,len);
        }
        osw.close();
        isr.close();

    }
}
